package com.dalongxin.work.page.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.andview.refreshview.recyclerview.BaseRecyclerAdapter;
import com.dalongxin.work.R;
import com.dalongxin.work.data.Project;

import java.util.List;

public class ProjectAdapter extends BaseRecyclerAdapter<ProjectAdapter.ProjectViewHolder> {

    private List<Project> mData;

    public ProjectAdapter(List<Project> mData) {
        this.mData = mData;
    }

    @Override
    public ProjectViewHolder getViewHolder(View view) {
        return new ProjectViewHolder(view, true);
    }

    @Override
    public ProjectViewHolder onCreateViewHolder(ViewGroup parent, int viewType, boolean isItem) {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_single_text, parent, false);
        return new ProjectViewHolder(v, true);
    }

    @Override
    public void onBindViewHolder(ProjectViewHolder holder, int position, boolean isItem) {
        if(mData != null) {
            Project item = mData.get(position);
            if (item != null) {
                holder.titleText.setText(item.getName());
            }
        }
    }

    @Override
    public int getAdapterItemCount() {
        return mData == null ? 0 : mData.size();
    }

    public class ProjectViewHolder extends RecyclerView.ViewHolder {

        private TextView titleText;
        public ProjectViewHolder(View itemView, boolean isItem) {
            super(itemView);
            titleText = itemView.findViewById(R.id.text_title);
        }
    }
}
